package com.qihoo.finance.fake.dao;

import com.qihoo.finance.fake.entity.FakeEntity;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface FakeDao {
    @Select("select id,interface_name,method_name,variety_type,variety_value,interface_state from c_fake_config where interface_state not in (3,4)")
    List<FakeEntity> selectAll();

    @Select("select id,interface_name,method_name,variety_type,variety_value,interface_state from c_fake_config where interface_name = #{i} and method_name = #{m}")
    FakeEntity selectOneByFullMethod(@Param("i") String interfaceName, @Param("m") String methodName);

    @Select("select id,interface_name,method_name,variety_type,variety_value,interface_state from c_fake_config where interface_state = 0")
    List<FakeEntity> selectNewMethod();

    @Update("update c_fake_config set interface_state = #{state} where id = #{id}")
    int updateInterfaceState(@Param("id") Long id, @Param("state") Integer state);

    @Select("select id,interface_name,method_name,variety_type,variety_value,interface_state from c_fake_config where interface_state = 3")
    List<FakeEntity> selectOfflineMethod();

    @Select("select variety_value from c_fake_db_variety_result where consumer_ip = #{ip} and interface_name = #{i} and method_name = #{m}")
    String selectFakeBaseDbIpResult(@Param("i") String interfaceName, @Param("m") String methodName, @Param("ip") String ip);

    @Select("select variety_type from c_fake_ip_variety_type where consumer_ip = #{ip}")
    String selectFakeVarietyByIp(String ip);

    @Select("select id,interface_name,method_name,variety_value,interface_state from c_fake_db_variety_result where consumer_ip = #{ip} and interface_state not in (3,4)")
    List<FakeEntity> selectFakeBaseDbIp(@Param("ip") String ip);

    @Select("select id,interface_name,method_name,variety_value,interface_state from c_fake_db_variety_result where consumer_ip = #{ip} and interface_state = #{state}")
    List<FakeEntity> selectFakeDbIpByState(@Param("ip") String ip, @Param("state") Integer state);

    @Update("update c_fake_db_variety_result set interface_state = #{state} where id = #{id}")
    int updateInterfaceStateDbIp(@Param("id") Long id, @Param("state") Integer state);
}
